﻿using iot.Commons;
using iot.Models;
using iot.Protocol;
using iot.Protocol.Smz;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace iot.Pages.SimensPages
{
    public partial class S7200Control : UserControl
    {
        private IPrototol? prototol { get; set; }

        public S7200Control()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (prototol == null)
            {
                MessageBox.Show("Protocol is not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var connect = prototol.Connect(new Models.PlcInfo
            {
                IP = input1.Text,
                PORT = input2.Text
            });
            if (connect)
            {
                AntdUI.Message.success(new AntdUI.Window(), "连接成功", Font);
            }
            else
            {
                AntdUI.Message.error(new AntdUI.Window(), "连接失败", Font);
            }
        }

        private void S7200Control_Load(object sender, EventArgs e)
        {
            prototol = new SimensS200Net();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (prototol == null)
            {
                MessageBox.Show("Protocol is not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            PointInfo pointInfo = new PointInfo();
            pointInfo.address = input3.Text;
            pointInfo.DetectionValue_Qty = 1;
            pointInfo.pointType = select1.Text.ToString();
            prototol.ReadData(pointInfo);
            MessageBox.Show("读取成功:" + pointInfo.Value);
           
        }
    }
}
